package RMIService;

import bean.Student;
import interfase.HelloRegistryFacade;
import util.JpaUtil;

import javax.persistence.EntityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * @author 24270
 */
public class HelloRegistryFacadeImpl extends UnicastRemoteObject implements HelloRegistryFacade {

    public HelloRegistryFacadeImpl() throws RemoteException {
        super();
    }

    @Override
    public String helloWorld(String name) {

        EntityManager manager = JpaUtil.getEntityManager();
        manager.getTransaction().begin();

        Student student = new Student();
        student.setName(name);
        student.setPhone("16622903367");
        student.setBarth("2021/10/14");

        manager.persist(student);
        manager.getTransaction().commit();
        manager.close();

        return "向数据库插入数据——>" + name + "成功";
    }

}

